﻿/*
 * GLLogicBase.h
 *
 *  Created on: Jun 12, 2014
 *      Author: yuliang
 */

#ifndef GLLOGICBASE_H_
#define GLLOGICBASE_H_

#include "GLGlobalProtocol.h"
#include <stdint.h>
#include <set>

class CGLLogicBase {
public:
	CGLLogicBase() : m_HasRegister(false), m_LogicName(std::string("UnknownLogic")) {}
	virtual ~CGLLogicBase() {}

	inline const std::string& GetLogicName() const { return m_LogicName; }
	inline void SetLogicName(const std::string& logic) { m_LogicName = logic; }

	inline bool HasRegister() const { return m_HasRegister; }
	inline void Register() { m_HasRegister = true; }

	inline void AddLogicType(uint32_t type) { m_Types.insert(type); }
	inline uint32_t LogicTypeSize() const { return m_Types.size(); }
	inline void AddExtendLogicType(uint32_t type) { m_ExtendTypes.insert(type); }
	inline bool ExistLogicType(uint32_t type) {
		return (m_Types.end() != m_Types.find(type) ||
				m_ExtendTypes.end() != m_ExtendTypes.find(type));
	}

	// 初始化(资源/业务)
	virtual void LogicInit() {}
	// 捕获此业务模块的业务包,是返回true,否则返回false
	virtual bool CatchLogic(const ProtocolBase *head, char * data, uint32_t len, void * connect) = 0;
protected:
	std::set<uint32_t>	m_Types;
	std::set<uint32_t>	m_ExtendTypes;
	bool				m_HasRegister;
	std::string			m_LogicName;
};

#endif /* GLLOGICBASE_H_ */
